package net.kazed.nextaction.context.activity;

import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.kazed.nextaction.R;
import net.kazed.nextaction.database.GtdContext;

public class ContextView extends LinearLayout {
	private TextView mName;
	private SparseIntArray mTaskCountArray;

	public ContextView(android.content.Context androidContext) {
		super(androidContext);
		
        LayoutInflater vi = (LayoutInflater) androidContext.
        		getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE);
        vi.inflate(getViewResourceId(), this, true); 
        
		mName = (TextView) findViewById(R.id.name);
	}
	
	protected int getViewResourceId() {
		return R.layout.context_view;
	}


	public void setTaskCountArray(SparseIntArray taskCountArray) {
		mTaskCountArray = taskCountArray;
	}
	
	public void updateView(GtdContext context, boolean isSelected) {
		if (mTaskCountArray != null) {
         Integer count = 0;
		   if (context.getId() != null) {
	         count = mTaskCountArray.get(context.getId());
	         if (count == null) {
	            count = 0;
	         }
		   }
			mName.setText(context.getName() + " (" + count + ")");
		} else {
			mName.setText(context.getName());
		}
	}

}
